// swiper插件设置
var mySwiper = new Swiper('.swiper', {
    navigation: { //左右切换
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
    autoplay: { //自动切换
        delay: 3000,
        stopOnLastSlide: false,
        disableOnInteraction: false,
    },
    loop: true, //循环
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    }, //分页器
    navigation: {//点击显示按钮
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
        hideOnClick: true,
    },
})


// api
let apiLi = document.querySelectorAll('#apiBottom li')
let apiImg = document.querySelectorAll('#apiBottom img')
let apiP = document.querySelectorAll('#apiBottom p')
// console.log(apiP);
// console.log(apiImg);
// console.log(li);
apiLi.forEach(function (dom, index) {
    // console.log(dom);
    //鼠标移入事件
    dom.addEventListener('mouseover', function () {
        this.style.backgroundColor = '#1271ef'
        apiP[index].style.color = '#fff'
        apiImg[index].src = `../images/api0${index+1}-c.svg`
        // console.log(apiImg[index]);
    })
    //鼠标移出事件
    dom.addEventListener('mouseout', function () {
        this.style.backgroundColor = '#fff'
        apiP[index].style.color = '#000'
        apiImg[index].src = `../images/api0${index+1}.svg`
    })
    // 鼠标点击跳转事件
    dom.addEventListener('click', function () {
        location.href = '#'
    })
})

// 银行轮播
let box = document.querySelectorAll('.help-bottom .box')
// console.log(box);
let index = 0;
// 遍历
let timeId = setInterval(runhouse, 2000)


// 鼠标移入跑马灯停止  移出后跑马灯继续
let helpBottom = document.querySelector('.help-bottom')
// console.log(helpBottom);
helpBottom.addEventListener('mouseover', function () {
    //鼠标移入
    clearInterval(timeId);
})
helpBottom.addEventListener('mouseout', function () {
    //鼠标移出
    timeId = setInterval(runhouse, 2000)
})
// 声明式
function runhouse() {
    // dom.classList.add('active')
    // console.log(box[index]);
    box[index].classList.remove('active');
    index++
    if (index === 3) {
        index = 0;
    };
    box[index].classList.add('active');
}
// 返回顶部按钮设置
let rTop = document.querySelector('#rTop')
//获取滚动条滚动距离，达到规定距离显示返回顶部按钮
window.addEventListener('scroll', function () {
    let num = document.documentElement.scrollTop //获取滚动条距离
    // console.log(num);
    if (num >= 1000) {
        rTop.style.display = 'block'
    } else {
        rTop.style.display = 'none'
    }
    // 鼠标移入按钮时按钮加深颜色
    rTop.addEventListener('mouseover', function () {
        rTop.style.backgroundPositionX = -163 + 'px';
        rTop.style.backgroundPositionY = -97 + 'px';
    })
    // 鼠标移出
    rTop.addEventListener('mouseout', function () {
        rTop.style.backgroundPositionX = -163 + 'px';
        rTop.style.backgroundPositionY = -56 + 'px';
    })
    // 点击返回顶部按钮，返回到顶部
    rTop.addEventListener('click', function () {
        window.scrollTo({
            top: 0,
            behavior: "smooth"
        })
    })
})